package org.lazy.generate.util;

import java.sql.ResultSetMetaData;

import org.lazy.generate.bean.GeneratorTable;
import org.lazy.util.StringUtil;

public class FactoryUtil {
	public final static String getPrimaryKeyJaveType(GeneratorTable table,ResultSetMetaData metaData,String dbType) throws Exception{
		String javaType = "Object";
		String primaryKey = table.getPrimaryKey();
		int colum = metaData.getColumnCount();
		for (int i = 1; i <= colum; i++) {
			int columnType = metaData.getColumnType(i);
			String columnName = metaData.getColumnName(i);
			if(StringUtil.isNotBlank(primaryKey)){
				if(primaryKey.toUpperCase().equals(columnName.toUpperCase())){
					String columnTypeName = metaData.getColumnTypeName(i);
					String fieldTypeName = SQLTypesUtil.getJavaType(columnType, columnTypeName,dbType);
					javaType = fieldTypeName;
					break;
				}
			}
		}
		return javaType;
	}
}
